<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <p>canvas 绘制矩形</p>
    <canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
        Your browser does not support the canvas element.
    </canvas>
    <script type="text/javascript">
        var c = document.getElementById("myCanvas");
        var cxt = c.getContext("2d");
        cxt.fillStyle = "#FF0000";
        cxt.fillRect(0, 0, 150, 75);
    </script>
    <hr />

    <p>canvas 绘制直线</p>
    <canvas id="myCanvas2" width="200" height="100" style="border:1px solid #c3c3c3;">
        Your browser does not support the canvas element.
    </canvas>
    <script type="text/javascript">
        var c = document.getElementById("myCanvas2");
        var cxt = c.getContext("2d");
        cxt.moveTo(10, 10);
        cxt.lineTo(150, 50);
        cxt.lineTo(10, 50);
        cxt.stroke();
    </script>
    <hr />

    <p>canvas 绘制直线</p>
    <canvas id="myCanvas3" width="200" height="100" style="border:1px solid #c3c3c3;">
        Your browser does not support the canvas element.
    </canvas>
    <script type="text/javascript">
        var c = document.getElementById("myCanvas3");
        var cxt = c.getContext("2d");
        cxt.fillStyle = "#FF0000";
        cxt.beginPath();
        cxt.arc(70, 18, 15, 0, Math.PI * 2, true);
        cxt.closePath();
        cxt.fill();
    </script>
    <hr />

    <p>canvas 绘制渐变</p>
    <canvas id="myCanvas4" width="200" height="100" style="border:1px solid #c3c3c3;">
        Your browser does not support the canvas element.
    </canvas>
    <script type="text/javascript">
        var c = document.getElementById("myCanvas4");
        var cxt = c.getContext("2d");
        var grd = cxt.createLinearGradient(0, 0, 175, 50);
        grd.addColorStop(0, "#FF0000");
        grd.addColorStop(1, "#00FF00");
        cxt.fillStyle = grd;
        cxt.fillRect(0, 0, 175, 50);
    </script>
    <hr />

    <p>canvas 绘制图像。图片是异步加载，执行js代码的时候图片还没有加载成功。许多对象会被频繁重绘。</p>
    <canvas id="myCanvas5" width="200" height="100" style="border:1px solid #c3c3c3;">
        Your browser does not support the canvas element.
    </canvas>
    <script type="text/javascript">
            var c = document.getElementById("myCanvas5");
            var cxt = c.getContext("2d");
            var img = new Image();
            img.src = "images/scene.jpg";
            img.onload = function(){cxt.drawImage(img,0,0);}
    </script>
</body>

</html>